package com.sisyphus.spinach.helper.validation;


/**
 * 效验工具
 */
public class FormValidation {

    public static FormValidation add(IFormRule... rules) {
        return new FormValidation(rules);
    }


    private IFormRule[] rules;


    private FormValidation(IFormRule... rules) {
        this.rules = rules;
    }


    public void start(ISuccessfulCallback successfulCallback, IFailedCallback failedCallback) {
        for (IFormRule rule : rules) {
            if (!rule.validation()) {
                failedCallback.failed(rule.getErrorMessage());
                return;
            }
        }

        successfulCallback.successful();
    }

}
